package com.mytaobao.main.firsttab.func.bannertop;

import android.content.Context;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.baseproject.adapter.ItemViewDelegate;
import com.baseproject.adapter.ViewHolder;
import com.baseproject.view.banner.BannerViewPager;
import com.mytaobao.R;
import com.mytaobao.util.Const;

/**
 * 顶部轮播
 */
public class BannerTopItemDelagate implements ItemViewDelegate<ItemBannerTop> {

    private ItemBannerTop mDataBannerTop;

    public BannerTopItemDelagate() {
        mDataBannerTop = new ItemBannerTop();
    }

    @Override
    public int getItemViewLayoutId() {
        return R.layout.banner_top;
    }

    @Override
    public int getItemViewType() {
        return Const.TYPE_BANNER_TOP;
    }

    @Override
    public void convert(ViewHolder holder, int position) {

    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        return false;
    }

    @Override
    public ViewHolder createViewHolder(Context context, ViewGroup parent) {
        View itemView = LayoutInflater.from(context).inflate(getItemViewLayoutId(), parent, false);
        ViewHolder holder = new BannerTopViewHolder(context, itemView);
        return holder;
    }

    private final class BannerTopViewHolder extends ViewHolder {
        public BannerTopViewHolder(final Context context, View itemView) {
            super(context, itemView);

            BannerViewPager bannerTop = (BannerViewPager) itemView.findViewById(R.id.bannerTop);
            bannerTop.setImagesUrl(mDataBannerTop.getBigPics());
            bannerTop.setOnItemClickListener(new BannerViewPager.OnItemClickListener() {
                @Override
                public void onItemClick(int position) {
                    Toast.makeText(context, "position--->" + position, Toast.LENGTH_SHORT).show();
                }
            });
        }
    }

    @Override
    public void updateData(ItemBannerTop itemBannerTop) {

    }

    @Override
    public int getItemCount() {
        return 1;
    }
}
